
import CascadedSelector from './components/cascadedSelector.vue'
import CellphoneCode from './components/cellphoneCode.vue'
import FixedMenu from './components/fixedMenu.vue'
import {EventBus} from './eventBus'
import VueForm from 'vue-form'
import Reserve from './components/reserve.vue'

var options = {
  inputClasses: {
    valid: 'form-control-success',
    'reserve': Reserve,
    invalid: 'form-control-danger'
  },
  validators: {
    'cellphone-validator': function(value, attrValue, vnode) {
      return /^\d{11}$/.test(value)
    }
  }
}

require('./app')({
  'cascadedSelector': CascadedSelector,
  'cellphoneCode': CellphoneCode,
  'fixedMenu' : FixedMenu
},function() {
    // EventBus.$on('getCellphoneInputStyle', style => {
    //this.style = style
    //})
  }, {
    formstate: {},
    style: '',
    contactName: '',
    cellphone: '',
    smsCode: '',
    street: '',
    address: '',
    desc: '',
    hiddenStreet: ''
  }, {}, {
    fieldClassName: function(field) {
      if (!field) {
        return '';
      }
      if ((field.$touched || field.$submitted) && field.$valid) {
        return 'has-success';
      }
      if ((field.$touched || field.$submitted) && field.$invalid) {
        return 'has-danger';
      }
    },
    passwordConfirmationValidator: function(value) {
      return value == this.model.password
    },
    onSubmit: function() {
      if (this.formstate.$invalid) {
        // alert user and exit early
        return;
      }
      $('form').submit()
      // otherwise submit form
    },
    formCallback: function(value) {
      this.street = value
    }
  }, [new VueForm(options)], {
    cellphone: function() {
      EventBus.$emit('getCellphone', this.cellphone)
    }
  }
)
